﻿Imports System.Data

Partial Class users_messages_Default
    Inherits System.Web.UI.Page

    Private _UserID As Integer
    Public Property UserID() As Integer
        Get
            Return _UserID
        End Get
        Set(ByVal value As Integer)
            _UserID = value
        End Set
    End Property

    Private _imgRead As Image
    Public Property imgRead() As Image
        Get
            Return _imgRead
        End Get
        Set(ByVal value As Image)
            _imgRead = value
        End Set
    End Property

    Private _imgUnread As Image
    Public Property imgUnread() As Image
        Get
            Return _imgUnread
        End Get
        Set(ByVal value As Image)
            _imgUnread = value
        End Set
    End Property


    Dim messageAdapter As New dsImagesTableAdapters.MessagesTableAdapter()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ID As FormsIdentity = DirectCast(HttpContext.Current.User.Identity, FormsIdentity)
        UserID = ID.Name
        gridMessages.DataSource = messageAdapter.GetMessagesByUserID(ID.Name)
        gridMessages.DataBind()

    End Sub

    Protected Sub gridMessages_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridMessages.DataBound

    End Sub


    'Protected Sub gridMessages_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridMessages.RowDataBound
    '    ' = 'dsImages.MessagesRow)
    '    Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)
    '    Dim isRead As dsImages.MessagesRow = CType(rowView.Row, DataRow)


    '    If isRead.Read = True Then
    '        gridMessages.Rows.Item(0).Cells(0).CssClass = "read"
    '        gridMessages.Rows.Item(0).Cells(0).Text = ""
    '    Else
    '        gridMessages.Rows.Item(0).Cells(0).CssClass = "unread"
    '        gridMessages.Rows.Item(0).Cells(0).Text = ""
    '    End If
    'End Sub

    Protected Sub gridMessages_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridMessages.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            ' Get the ProductsRow object from the DataItem property...
            Dim isRead As dsImages.MessagesRow = DirectCast(DirectCast(e.Row.DataItem, System.Data.DataRowView).Row, dsImages.MessagesRow)
            If isRead.Read = True Then
                e.Row.Cells(0).CssClass = "read"
                e.Row.Cells(0).Text = ""
                Dim gridIndex As Integer = gridMessages.Rows.Count

            Else
                e.Row.Cells(0).CssClass = "unread"
                e.Row.Cells(0).Text = ""
            End If

        End If
    End Sub

    Protected Sub gridMessages_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridMessages.SelectedIndexChanged
        Dim messageID As Integer = gridMessages.SelectedDataKey.Value

        messageAdapter.MessageRead(True, messageID)

        Response.Redirect("readMessage.aspx?MessageID=" & messageID)
    End Sub


End Class
